﻿using CoreShop.Model;
using Sunny.UI;
using System.Threading;

namespace CoreShop.App
{
    public partial class FOrder : UIForm
    {
        public FOrder()
        {
            InitializeComponent();
        }

        private void Form1_Shown(object sender, System.EventArgs e)
        {
            timer1.Start();
        }

        private void Item_Click(object sender, System.EventArgs e)
        {
            UIDishItem item = (UIDishItem)sender;
            ShowInfoTip(item.Info.Name);
        }

        private void uiSymbolButton11_Click(object sender, System.EventArgs e)
        {
            if (uiPanel8.Text.ToInt() > 1)
                uiPanel8.Text = (uiPanel8.Text.ToInt() - 1).ToString();
        }

        private void uiSymbolButton12_Click(object sender, System.EventArgs e)
        {
            uiPanel8.Text = (uiPanel8.Text.ToInt() + 1).ToString();
        }

        private void uiLabel3_Click(object sender, System.EventArgs e)
        {
            uiTextBox2.Text = "";
        }

        private void uiButton5_Click(object sender, System.EventArgs e)
        {
            //UIToolStripDropDown Discounts = new UIToolStripDropDown(new UIDiscounts(null,0));
            //Discounts.ValueChanged += Discounts_ValueChanged;
            //Discounts.Show(uiPanel5, 0, 0);
        }

        private void Discounts_ValueChanged(object sender, object value)
        {
            DicountInfo info = (DicountInfo)value;
            ShowInfoTip(uiButton5, info.Desc + "," + info.Value + "%");
        }

        private void uiSymbolButton8_Click(object sender, System.EventArgs e)
        {
            UIToolStripDropDown Payment = new UIToolStripDropDown(new UIPayment());
            Payment.ValueChanged += Payment_ValueChanged;
            Payment.Show(uiPanel5, 0, 0);
        }

        private void Payment_ValueChanged(object sender, object value)
        {
            throw new System.NotImplementedException();
        }

        private void timer1_Tick(object sender, System.EventArgs e)
        {
            timer1.Stop();
            ShowStatusForm(45);
            Thread.Sleep(100);

            //加载商品数据
            uiFlowLayoutPanel1.Clear();
            for (int i = 0; i < 36; i++)
            {
                DishItemInfo dish = new DishItemInfo();
                if (i.Mod(5) == 0)
                    dish.Name = "芝麻虾球芝麻虾球芝麻虾球";
                else
                    dish.Name = "芝麻虾球";

                if (i.Mod(7) == 0)
                    dish.LabelExist = "剩 10,000 份";

                dish.Money = RandomEx.RandomNumber(2);

                if (i.Mod(4) == 0)
                    dish.DiscountString = "3个优惠";

                var item = new UIDishItem(dish);

                if (i.Mod(8) == 0)
                    item.TipsText = RandomEx.RandomNumber(1);

                item.Margin = new System.Windows.Forms.Padding(3);
                item.Click += Item_Click;
                uiFlowLayoutPanel1.Add(item);
                StatusFormStepIt();
            }

            //加载菜单数据
            uiFlowLayoutPanel2.Clear();

            MenuItemInfo info = new MenuItemInfo();
            info.Code = "6923994500476";
            info.Name = "四塘桂花马蹄四塘桂花马蹄四塘";
            info.Count = "15个";
            info.Money = "25";
            info.IsReturning = true;
            AddMenu(info);

            info = new MenuItemInfo();
            info.Code = "69266794500476";
            info.Name = "金沙蒜香牛肉";
            info.Count = "1斤";
            info.Price = "59.5";
            info.Money = "59";
            info.Tags.Add("做法：不辣");
            AddMenu(info);

            info = new MenuItemInfo();
            info.Name = "桂花马蹄爽";
            info.Count = "1";
            info.Money = "9";
            info.Price = "259.5";
            info.Tags.Add("做法：不辣");
            info.Tags.Add("备注：免香菜，干椒酸笋，加急，快点等不急了，加急，快点等不急了");
            AddMenu(info);

            info = new MenuItemInfo();
            info.Name = "四塘桂花马蹄1";
            info.Count = "1";
            info.Money = "25";
            info.Price = "9.5";
            AddMenu(info);

            info = new MenuItemInfo();
            info.Name = "四塘桂花马蹄2";
            info.Count = "1";
            info.Money = "25";
            AddMenu(info);

            info = new MenuItemInfo();
            info.Name = "四塘桂花马蹄3";
            info.Count = "1";
            info.Money = "25";
            AddMenu(info);

            info = new MenuItemInfo();
            info.Name = "四塘桂花马蹄4";
            info.Count = "1";
            info.Money = "25";
            AddMenu(info);

            info = new MenuItemInfo();
            info.Name = "四塘桂花马蹄5";
            info.Count = "1";
            info.Money = "25";
            AddMenu(info);

            var sp = new UIMenuItemSeparator();
            uiFlowLayoutPanel2.Add(sp);

            info = new MenuItemInfo();
            info.Name = "秘制桃花酿";
            info.Count = "1";
            info.Money = "0";
            info.Discounts = "25";
            info.IsPresent = true;
            AddMenu(info);

            HideStatusForm();
        }

        private void AddMenu(MenuItemInfo info)
        {
            var menu = new UIMenuItem(info);
            uiFlowLayoutPanel2.Add(menu);
            StatusFormStepIt();
        }

        private void uiButton13_Click(object sender, System.EventArgs e)
        {
            var btn = (UIButton)sender;
            btn.Selected = true;
        }

        private void uiButton14_Click(object sender, System.EventArgs e)
        {
            var btn = (UIButton)sender;
            btn.Selected = true;
        }

        private void uiButton2_Click(object sender, System.EventArgs e)
        {
            var btn = (UIButton)sender;
            btn.Selected = true;
        }

        private void uiButton1_Click(object sender, System.EventArgs e)
        {
            var btn = (UIButton)sender;
            btn.Selected = true;
        }

        private void uiSymbolButton1_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }
    }
}
